package com.ms.education.statistics.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ms.education.R;
import com.ms.education.statistics.entity.StatisticsDaily;
import com.ms.education.statistics.service.StatisticsDailyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author ms
 * @since 2023-01-22
 */
@RestController
@RequestMapping("/statistics/statistics-daily")
public class StatisticsDailyController {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    @SaCheckRole("超管")
    @GetMapping("getAllStatistics")
    public R getAllStatistics(String beginTime, String endTime) {
        QueryWrapper<StatisticsDaily> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(beginTime)) {
            wrapper.ge("date_calculated", beginTime);
        }
        if (!StringUtils.isEmpty(endTime)) {
            wrapper.le("date_calculated", endTime);
        }
        if (StringUtils.isEmpty(beginTime) && StringUtils.isEmpty(endTime)) {
            wrapper.last("limit 20");
        }
        wrapper.orderByAsc("date_calculated");
        List<StatisticsDaily> list = statisticsDailyService.list(wrapper);
        return R.ok().data("statistic", list);
    }

}
